<?php

class Admin_AutocompleteController extends Zend_Controller_Action {

    protected $_pattern;

    public function init() {
        $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout->disableLayout();
        $this->_pattern = $this->_getParam("pattern");
    }

    public function preDispatch() {
        // Autenticacion del usuario
        $auth = Zend_Auth::getInstance();
        if (!$auth->hasIdentity()) {
            $this->_helper->layout->disableLayout();
            $this->_forward("index", "index", "");
        } else {
            $identity = $auth->getIdentity();
            if ($identity['tipo_usuario'] != VirtualLabs_Admin_Usuario::ROL_ADMIN) {
                $this->_helper->layout->disableLayout();
                $this->_redirect('/');
            }
        }
        //fin de la autenicacion del usuario
    }

    public function areaacademicaAction() {
        echo Zend_Json_Encoder::encode();
    }

    public function alumnosAction() {
        $usuario = new VirtualLabs_Admin_Usuario();
        $listaAlumnos = $usuario->getAlumnoByPattern($this->getRequest()->getParam('term'));
        $response = array();
        foreach ($listaAlumnos as $value) {
            $response[] = array('value' => $value['nombre'] . " " . $value['apellido'],
                'label' => $value['nombre'] . " " . $value['apellido'],
                'id' => $value['nombre'] . "#" . $value['apellido'] . "#" . $value['email'] . "#" . $value['username']);
        }
        echo Zend_Json_Encoder::encode($response);
    }

}
